using Abp.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Xwy.MyProject.Entities;
using Xwy.MyProject.IRepositories;

namespace Xwy.MyProject.EntityFrameworkCore.Repositories
{
    public class ProductRepository : MyProjectRepositoryBase<Product>, IProductRepository
    {
        public ProductRepository(IDbContextProvider<MyProjectDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public bool Delete(string ids)
        {
            var idList = ids.Split(',');
            Expression<Func<Product, bool>> exp = m => idList.Contains(m.Id.ToString());

            bool result = true;
            Delete(exp);
            return result;
        }

        public IEnumerable<Product> LoadProducts(int pageindex, int pagesize)
        {
            return Context.Products.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize);
        }
    }
}
